-- wtf.lua
-- Turns the hub into a madhouse!
-- Tyrone - Sam - 2007

---------------------------------------
_, hubsecurityname = VH:GetConfig("config", "hub_security")
-- set up all command prefixes
cmdNames = {
}

-- content arrays go here

-- all our /me loves men content
yamen = {
    "/me loves the men!1!!fourteen!!",
    "OMFG I AM SO GAY!",
	"HOLY SHIT I LIKE THE DICK IN MY ANUS",
	"Guys, I've decided that this DC network would be the most appropriate place to make this announcement... *sigh*, I'm a homosexual.  There, I've said it."
}

letters = {
	"a",
	"t",
	"c",
	"s",
	"e",
	"h"
}

insults = {
	" likes to bat themselves in public!",
	" watches BEASTIALITY PORN, WTF.",
	" is a flaming homosexual.  Full stop.",
	" had sex with YOUR SISTER.  True story.",
	" is made of epic fail and gay.  Oh, and they keep gay porn on their computer.",
	" is into the BDSM.  'nuff said.",
	" likes scat - need I say more?",
	" is a huge faggot.",
	" is having sexual relations with your female parental unit as we speak!",
	" is having sexual relations with your MALE PARENTAL UNIT as we speak!  THAT'S JUST NASTY.",
	" has http://gade.ath.cx loaded in a firefox window 24/7.",
	" will choose cock, even if not given a choice."
}
-- end content arrays

COOLDOWN = 10 -- plugin cooldown, 0 for none
bot_name = "YourMum"
bot_desc = "bot description here"
bot_email = "bot@nowhere.com"
use_bot = false

function doHelp(nick)
    SendMessageToUser("Usage: ", nick, bot_name)
    DisplayHelpMessage("help", "Shows this message.", nick)
    -- put coad in here for help commands:
    DisplayHelpMessage("", "does something here", nick)
end

-- insert other functions here
---------------------------------------
-- you can ignore below here
timeLeft = COOLDOWN


function VH_OnParsedMsgChat(nick, data)
	rnd = math.random(0,18)
	if (rnd == 0) then
		--this person announces they are gay
		SendMessageToHub(yamen[math.random(1,table.maxn(yamen))], nick)
		return 0
	elseif (rnd == 1) then
		--ends their own life "OH SHI-"
		SendMessageToHub(string.sub(data, 1, string.len(data)/2).."OH SHI-", nick)
		VH:CloseConnection(nick)
		return 0
	elseif (rnd == 2) then
		--speak in SPARTA mode
		if (string.find(data, "^[%.%+!/]")) then
    		return 1
    	else
    		SendMessageToHub(string.gsub(data, "[aA]", "AAAAAAAA"), nick)
    	    return 0
    	end
	elseif (rnd == 3) then
		--remove all vowels from sentence
		if (string.find(data, "^[%.%+!/]")) then
    		return 1
    	else
			SendMessageToHub(string.gsub(data, "[aAeEiIoOuU]+", ""), nick)
			return 0
		end
	elseif (rnd == 4) then
		--reverse their text
		if (string.find(data, "^[%.%+!/]")) then
    		return 1
    	else
			SendMessageToHub(string.reverse(data), nick)
			return 0
		end
	elseif (rnd == 5) then
		--replaces text with all caps
		if (string.find(data, "^[%.%+!/]")) then
    		return 1
    	else
			SendMessageToHub(string.upper(data), nick)
			return 0
		end
	elseif (rnd == 6) then
		--adds *ler*
		if (string.find(data, "^[%.%+!/]")) then
    		return 1
    	else
			SendMessageToHub(data.." *ler*", nick)
			return 0
		end
	elseif (rnd == 7) then
		--randomly adds "MAH BALLS" between words
		if (string.find(data, "^[%.%+!/]")) then
			return 1
		else
			SendMessageToHub(string.gsub(data, " ", " MAH BALLS "), nick)
			return 0
		end
	elseif (rnd == 8) then
		--changes some letters into leet
		if (string.find(data, "^[%.%+!/]")) then
    		return 1
		else
			replaced = ""
			replaced = string.gsub(data, "[aA]", "4")
			replaced = string.gsub(replaced, "[eE]", "3")
			replaced = string.gsub(replaced, "[iI]", "1")
			replaced = string.gsub(replaced, "[oO]", "0")
			replaced = string.gsub(replaced, "[tT]", "7")
			replaced = string.gsub(replaced, "[gG]", "9")
			replaced = string.gsub(replaced, "[rR],", "12")
			replaced = string.gsub(replaced, "[lL]", "1")
			SendMessageToHub(replaced, nick)
			return 0
		end
	elseif (rnd == 9) then
		--censors lots of text
		if (string.find(data, "^[%.%+!/]")) then
    		return 1
    	else
			replaced = ""
			replaced = string.gsub(data, letters[math.random(1,table.maxn(letters))].."[a-zA-Z]+", "****")
			SendMessageToHub(replaced, nick)
			return 0
		end
	elseif (rnd == 10) then
		--piratises their text (adds *yarr!* and [aA] becomes AAARRR)
		if (string.find(data, "^[%.%+!/]")) then
			return 1
		else
			SendMessageToHub(string.gsub(data, "[aA]+", "AAARRR").." *yarr!*", nick)
			return 0
		end
	else
		return 1
	end
end

function Main()
	SendMessageToHub("OOOOHHHHH NOOOOEESSS!!!  WTF.LUA HAS BEEN ACTIVATED.  BRACE YOURSELVES FOR MAYHEM!!!", hubsecurityname)
end

function UnLoad()
	SendMessageToHub("wtf.lua has been deactivated.  Normality restored.", hubsecurityname)
end

function SendMessageToHub(data, from)
	return VH:SendDataToAll("<"..from.."> "..data.."|",0,10)
end

function SendMessageToUser(data, nick, from)
	return VH:SendDataToUser("<"..from.."> "..data.."|", nick)
end

function SendPrivateMessageToUser(user, data, from)
    return VH:SendDataToUser("$To: "..user.." From: "..from.." $<"..from.."> "..data.."|", user);
end

function DisplayHelpMessage(cmd, msg, nick)
    SendMessageToUser("        ."..cmdNames[1].." "..cmd, nick, bot_name)
    SendMessageToUser("        "..msg, nick, bot_name)
end

function GetOnlineUsers()
	tableOut = {}
	_,nicklist = VH:GetNickList()
	for names in string.gmatch(nicklist, "([^%$]+)%$%$") do
		if (UserIsOnline(names)) then --they aren't a bot
			table.insert(tableOut, names)
		end
	end
	return tableOut
end

function UserIsOnline(nick)
	result, sIP = VH:GetUserIP(nick)
	if (string.len(sIP) < 7) then
		return false
	else
		return true
	end
end

function VH_OnTimer()
	if (timeLeft == 0) then
		rnd = math.random(0,6)
		currentUsers = GetOnlineUsers()
		if (rnd == 0) then
			--god farts on someone's connection
			kicked = ""
			kicked = currentUsers[math.random(1, table.maxn(currentUsers))]
			SendMessageToHub("/me farts all over "..kicked.."'s connection.", hubsecurityname)
			VH:CloseConnection(kicked)
		elseif (rnd == 1) then
			--god insults people
			insulted = ""
			insulted = currentUsers[math.random(1, table.maxn(currentUsers))]
			SendMessageToHub(insulted..insults[math.random(1, table.maxn(insults))], hubsecurityname)
		elseif (rnd == 2) then
			--some random on the hub will announce they like the penis
			randomgay = ""
			randomgay = currentUsers[math.random(1, table.maxn(currentUsers))]
			SendMessageToHub(yamen[math.random(1, table.maxn(yamen))], randomgay)
		elseif (rnd == 3) then
			--tumbleweed rolls past
			SendMessageToHub("/me rolls past!", "Tumbleweed")
		elseif (rnd == 4) then
			--daddy says rape time!
			SendMessageToHub("/me says: Rape time!", "Daddy")
		elseif (rnd == 5) then
			--god hears sex noises
			SendMessageToHub("/me hears: sex noises", "God")
		elseif (rnd == 6) then
			--satan feels your ass
			SendMessageToHub("/me feels your ass.", "Satan")
		end
		timeLeft = COOLDOWN
	else
		timeLeft = timeLeft - 1
	end
	return 1
end

